window.onload = function() {
    let startX = 0; //手指初始接触时坐标x
    let endX = 0;   //手指滑动时坐标x
    let scrollBarLeft = 0; //滚动条left值

    let scrollBox = document.getElementById("scrollBox");//滚动条容器
    let scrollBar = document.getElementById("scrollBar");//滚动条

    //左滚动最值（容器宽度-滚动条长度）
    let stop = scrollBox.offsetWidth - scrollBar.offsetWidth;

    scrollBox.addEventListener('touchstart',function(event) {
        let touch = event.targetTouches[0];
        startX = touch.pageX;
        scrollBarLeft = scrollBar.offsetLeft;
    }, false);

    scrollBox.addEventListener('touchmove',function(event) {
        let touch = event.targetTouches[0];
        endX = touch.pageX;
        scrollBarLeft = scrollBar.offsetLeft;
        let len = (endX - startX) + scrollBarLeft;
        if(len >= 0) len = 0;
        if(len <= stop) len = stop;
        scrollBar.style.left = len + 'px';
    }, false);

}